package com.habdqn.dubbo.spring.boot.demo.controller;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.habdqn.dubbo.spring.boot.demo.entity.Detail;
import com.habdqn.dubbo.spring.boot.demo.service.DetailService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 帖子明细表(Detail)表控制层
 *
 * @author xing.jiejian
 * @since 2019-04-10 14:56:11
 */
@Controller
@RequestMapping("/detail2")
public class DetailController2 {
    /**
     * 服务对象
     */
    @Reference(version = "${demo.service.version}",url = "${demo.service.url}")
    private DetailService detailService;


    @GetMapping("/page/{pageNo}")
    public String list(@PathVariable("pageNo") int pageNo, Model model){
        IPage<Detail> details = detailService.queryAllByPage(pageNo,5);
        model.addAttribute("result",details);
        return "details";
    }

    @PostMapping("/page")
    public String listBySortId(@RequestParam(defaultValue = "1",name = "pageNo") int pageNo,@RequestParam(name = "sortId",defaultValue = "0") int sortId, Model model){
        IPage<Detail> details = detailService.findPageBySortId(pageNo,5,sortId);
        model.addAttribute("result",details);
        return "details";
    }
}